package com.spring.team_propaganda_system.utils;
import lombok.Getter;

import java.io.Serializable;

/**
 * <p>
 * Result
 * </p>
 *
 * @author biubiu
 * @since 2021/1/23
 */
@Getter
public class Result<T> implements Serializable {
    private static final long serialVersionUID = -1L;

    private final int code;
    private final String message;
    private final T data;

    private Result(IResultCode resultCode, T data) {
        this.code = resultCode.getCode();
        this.message = resultCode.getMessage();
        this.data = data;
    }

    private Result(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static <T> Result<T> success() {
        return success(null);
    }

    public static <T> Result<T> success(T data) {
        return new Result<>(ResultCode.SUCCESS, data);
    }


    public static <T> Result<T> error() {
        return error(ResultCode.ERROR);
    }

    public static <T> Result<T> error(ResultCode resultCode) {
        return new Result<>(resultCode, null);
    }

    public static <T> Result<T> error(String message) {
        return new Result<>(ResultCode.ERROR.getCode(), message, null);
    }

}